import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return HomeState();
  }
}

class HomeState extends State<HomePage> {
  static const methodChannel = const MethodChannel('ace_demo_android_flutter');
  String _result = '点击我，给客户端发送东西';

  _getInvokeResult() async {
    try {
      _result = await methodChannel
          .invokeMethod('flutter_to_android', {'name': '我太帅了'});
    } on PlatformException catch (e) {
      _result = "Failed: '${e.message}'.";
    }
    setState(() {});
  }

  _incrementCounter() {
    setState(() {
      _getInvokeResult();
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      child: GestureDetector(
        child: Text(
          _result,
          style: TextStyle(color: Colors.black, fontSize: 18.0),
        ),
        onTap: this._incrementCounter,
      )
    );
  }
}
